package util

import (
	"ginfast/pkg/ctx"
	"ginfast/pkg/orm"

	"github.com/gin-gonic/gin"
)

func Deletes(v interface{}, c *gin.Context) {
	idstr := c.Param("id")
	if idstr != "" {
		ids := StringSplit(idstr, ",")
		if err := orm.DbDeleteByIDs(v, ids); err != nil {
			ctx.JSONWriteError(err, c)
			return
		}
	}
	ctx.JSONWriteData(nil, c)
}

func QueryByID(v interface{}, c *gin.Context) {
	queryId := ctx.ParamUInt(c, "id")
	if err := orm.DbFirstByID(v, queryId); err != nil {
		ctx.JSONWriteError(err, c)
		return
	}
	ctx.JSONWriteData(v, c)
}
